# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Milan P. Stanić <mps@arvanta.net>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=zig
pkgver=0.9.1
pkgrel=0
pkgdesc="general-purpose programming language designed for robustness, optimality, and maintainability"
url="https://ziglang.org/"
arch="x86_64 aarch64"
license="MIT"
provides="zig-dev=$pkgver-r$pkgrel"
#subpackages="$pkgname-doc" # disable for now, fails on build
options="!check" # fail, disable to unblock builders
makedepends="cmake clang-dev clang-libs llvm13-libs llvm-dev lld-dev libstdc++
	zlib-static libxml2-dev llvm13-static clang-static"
source="$pkgname-$pkgver.tar.gz::https://github.com/ziglang/zig/archive/$pkgver.tar.gz
	llvm-include.patch"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	mkdir -p build
	cd build
	cmake \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DZIG_VERSION="$pkgver" \
		${CMAKE_CROSSOPTS} \
		..
	make
}

check() {
	cd build
	./zig build test \
		-Dskip-release \
		-Dskip-release-small \
		-Dskip-release-fast \
		-Dskip-non-native \
		-Dskip-libc
}

package() {
	make -C build DESTDIR="$pkgdir" install

	# Documentation is generated as part of `./zig build test` in check().
	# If this is no longer the case at some point it can be
	# generated explicitly using `./zig build docs`.
	### it is not built now ###
	#install -Dm644 zig-cache/langref.html \
	#	"$pkgdir"/usr/share/doc/$pkgname/langref.html
}

sha512sums="
a9dc5fea25dde511122056832449658b00dbcf6d6bbfe658b375968a7bdb06c690abbdfe00c1afcfa481442392b051dcef5a5a5e81d4ceb23fa98a866b900f37  zig-0.9.1.tar.gz
3d7a3f5ad1ba753bf8cffa7ddbb6785b9dec195121aad15b4ae66bac7123a84e0eb2cc347fcc8193b90a3e84abc99a8bfc9a77ab9205b14e6c0bdaaa20ce889a  llvm-include.patch
"
